class NumError(Exception):
    def __init__(self,num):
        self.num = num
    def __str__(self):
        return f"商品数量不能小于0, 当前输入为{self.num}"

class Buy:
    def number(self):
        try:
            num = float(input('请输入购入的商品数量'))
            if num < 0:
                raise NumError(num)
        except NumError as e:
            print(e)
buy = Buy()
buy.number()

